#ifndef STM32F10X_DEVBOARD_RGB_H
#define STM32F10X_DEVBOARD_RGB_H

#include <stdbool.h>
#include "spi.h"

#define LED_NUMBER 128
#define MAX_BREATH_LIGHT 0.8
#define MIN_BREATH_LIGHT  0.1
#define HIGH 0xFE
#define LOW 0xE0

volatile static bool rhythm = true;
static uint8_t rhythmDiv = 0;
volatile static bool breathe = true;;
static float breatheDiv = 0;;
static float brightness = MIN_BREATH_LIGHT;
static uint8_t rgbBuffer[LED_NUMBER][3][8];
static uint8_t brightnessPreDiv = 1; // 1/4
volatile static bool isRgbTxBusy;

typedef struct {
    uint8_t r;
    uint8_t g;
    uint8_t b;
}Color_t ;
static Color_t RAINBOW_Color[15] = {
        (Color_t){0xFF, 0x00, 0x00},    //red
        (Color_t){0xFF, 0x99, 0x00},    //orange
        (Color_t){0xFF, 0xFF, 0x00},    //yellow
        (Color_t){0x66, 0xFF, 0x00},
        (Color_t){0x00, 0xFF, 0x00},    //green
        (Color_t){0x00, 0xFF, 0x66},
        (Color_t){0x00, 0xFF, 0xFF},    //cyan
        (Color_t){0x00, 0x66, 0xFF},
        (Color_t){0x00, 0x00, 0xFF},    //blue
        (Color_t){0x66, 0x00, 0xFF},
        (Color_t){0x99, 0x00, 0xFF},    //purple
        (Color_t){0xFF, 0x00, 0xFF},
        (Color_t){0xFF, 0x00, 0x66},
        (Color_t){0xFF, 0xFF, 0xFF},    //white
        (Color_t){0x00, 0x00, 0x00},    //black
};
enum colorEnum {
    RED, ORANGE, YELLOW, GREEN = 4, CYAN = 6, BLUE = 8, PURPLE = 10, WHITE = 13, BLACK,
};


#ifdef __cplusplus
extern "C" {
#endif
    /**
     * RGB初始化
     */
    void RGBInit(void);
    /**
     * 获取ID
     * @param x
     * @param y
     * @return
     */
    uint8_t getIdByMatrix(uint8_t x, uint8_t y);
    /**
     * 设置RGB
     *
     * @param _keyId RGBIndex
     * @param _color 颜色
     * @param _brightness 亮度
     */
    void SetRgbBufferByID(uint8_t _keyId, Color_t _color, float _brightness);
    void setIsRgbTxBusy(bool isRgbTxBusy);
    /**
     * 同步灯光
     */
    void SyncLights();
    /**
     * 随机颜色
     *
     * @param seed 随机数种子
     */
    Color_t ColorRand(uint8_t seed);
    /**
     * 呼吸
     */
    void breatheEffect(Color_t color);
    /**
     * 律动
     */
    void rhythmEffect();
    /**
     * 简单律动
     */
    void simpleRhythmEffect(uint8_t div);
    /**
     * 音乐律动
     *
     * @param power 功率
     */
    void musicRhythmEffect(uint8_t power, Color_t color);
    /**
     * 彩虹
     */
    void rainbowEffect();
#ifdef __cplusplus
}
#endif


#endif //STM32F10X_DEVBOARD_RGB_H
